package user_service

import (
	"go_essential/database"
	"go_essential/entity"
	"go_essential/tool"
)

// 创建用户
func CreateUser(user *entity.User) bool {
	err := database.MDB.Create(user)
	return err.Error == nil
}

// 验证用户登录
// 要求用户名和密码同时相同
func UserLogin(username string, password string) bool {
	userList := []entity.User{}
	database.MDB.Raw("select * from tb_user where username = ?", username).Scan(&userList)
	if len(userList) == 0 {
		return false
	}
	hashPassword := userList[0].Password
	return tool.CheckPassword(password, hashPassword)
}

